package net.adetech.cjg.innerservice.controller;


import net.adetech.cjg.innerservice.utils.InnerServiceUtils;
import net.adetech.framework.entity.ServiceRequest;
import net.adetech.framework.entity.ServiceResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.Date;

@RestController
public class BankController {

    @Autowired
    InnerServiceUtils serviceUtils;



    private static int index = 1;

    @RequestMapping("/cjg/submit")
    public String submit( String input){
        System.out.println(input);
        String date = new SimpleDateFormat("yyyyMMdd").format(new Date());
        String orderNum = getSeq();
        ServiceResponse response = serviceUtils.callService("bank.buildOrder","orderNum",orderNum,"amount","0.01");
        String result = (String)response.getResults().get("result");
        return result;
    }


    private String getSeq()
    {
        String seq = new SimpleDateFormat("yyyyMMdd").format(new Date());
        if (index<10)
        {
            seq += "0000";
        }
        else if (index<100)
        {
            seq += "000";
        }
        else if (index<1000)
        {
            seq += "00";
        }
        else {
            seq += "0";

        }
        seq += index;
        index++;
        System.out.print("index-------------->"+index);
        return seq;
    }
}
